﻿@model IEnumerable<TaskManager_WCG.Models.Task>

@{
    ViewBag.Title = "主页";
}

<h2>任务列表</h2>
<form method="get" class="form-inline text-center" style="margin:10px">
    所属用户：@Html.DropDownList("uid", null, new { @class = "form-control" })
    任务内容：<input type="text" name="Content" class="form-control" placeholder="请输入内容关键字" />
    @*任务状态：<input type="radio" name="State" class="form-control" value="1" />未完成
        <input type="radio" name="State" class="form-control"  value="1"/>已完成*@
    <input type="submit" value="查询" class="btn btn-primary" />
</form>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.TaskPriority)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TaskState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FinishedTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.UserInfo.name)
        </th>
        <th>操作</th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.TaskPriorityStr)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Content)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.AddTime)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.TaskStateStr)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FinishedTime)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.UserInfo.name)
        </td>
        <td>
            @Html.ActionLink("修改", "Edit", new { id = item.TaskID }) |
            @Html.ActionLink("详情", "Details", new { id = item.TaskID }) |
            @*@Html.ActionLink("删除", "Delete", new { id=item.TaskID })*@
            <a href="#" data-del="@item.TaskID">删除</a>
        </td>
    </tr>
}

</table>
@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-del");
                if (!confirm("你确定要删除吗？")) {
                    return;
                }
                $.post("@Url.Content("~/Home/Delete")", { id: id }, function (res) {
                    if (res) {
                        //局部刷新（删除选中行）
                        $this.closest("tr").remove();
                        alert("删除成功");
                    }
                })
            })
        })
    </script>
    
    
    
    }
